﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Component;

public partial class BackEnd_ImageControl : System.Web.UI.UserControl
{
    public string _UrlModify = BackEndQuery._AdminQuery + BackEndQuery._ImagesModify + "&" + ConstString._idcat + ConstString._dauBang;
    public string UrlImages = "";
    protected void Page_Load(object sender, EventArgs e)
    {        
        Load_Data();
        grid.RowCommand += new GridViewCommandEventHandler(grid_RowCommand);
    }

    void grid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       
        if (e.CommandName == "lbtNewSub")
        {
            Response.Redirect(_UrlModify + e.CommandArgument.ToString());
        }
    }

    private void Load_Data()
    {
        grid.DataKeyNames = new string[] { ColumImages._Id };
        grid.DataSource = ImageDB.GetAll();
        grid.DataBind();
    }

    protected void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            object id = grid.DataKeys[e.RowIndex].Value;
            if (ImageDB.Delete((int)id))
                this.labMessage.Text = ConstString._xoaTC;
            else
                labMessage.Text = ConstString._xoaTB;
        }
        catch { }
        Load_Data();
    }
    protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grid.PageIndex = e.NewPageIndex;
        Load_Data();
    }
}
